//
//  TwoDimensionCodeViewController.m
//  CPICMobileServiceApp
//
//  Created by lizhiwei on 13-2-18.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "TwoDimensionCodeViewController.h"
#import "ZBarSDK.h"
#import "QRCodeGenerator.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "RCAlertViewUtil.h"

@interface TwoDimensionCodeViewController ()

@end

@implementation TwoDimensionCodeViewController
@synthesize ScanningBtn;
@synthesize UrlBtn;
@synthesize SmsBtn;
@synthesize ContactInfoBtn;
@synthesize CancelBtn;
@synthesize imageview;
@synthesize UrlContent;
@synthesize Reader;
@synthesize Number;
@synthesize Message;
@synthesize theArray;
@synthesize SmsContent;
@synthesize ContactInfoContent;
@synthesize ContactInfoArray;
@synthesize FirstName;
@synthesize FamilyName;
@synthesize Telephone;
@synthesize CallNumber;
@synthesize FaxTelephone;
@synthesize Email;
@synthesize CompanyUrl;
@synthesize Street;
@synthesize City;
@synthesize Province;
@synthesize PostalCode;
@synthesize Company;
@synthesize JobTitle;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"二维码扫描";
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"二维码扫描");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"二维码扫描");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"二维码扫描");        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    //添加背景色
    UILabel * bgcolor = [[UILabel alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 50)];
    bgcolor.backgroundColor = [UIColor blackColor];
    [self.view addSubview:bgcolor];
    [bgcolor release];
    
    //添加扫描按钮
    ScanningBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    ScanningBtn.frame = CGRectMake(0, 44, self.view.frame.size.width/4, 50);
    [ScanningBtn setImage:[UIImage imageNamed:@"TwoDimensional_01"] forState:UIControlStateNormal];
    [ScanningBtn setTitle:@"扫描" forState:UIControlStateNormal];
    [ScanningBtn addTarget:self action:@selector(ClickScanningBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:ScanningBtn];
    
    //添加URL按钮
    UrlBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UrlBtn.frame = CGRectMake(self.view.frame.size.width/4, 44, self.view.frame.size.width/4, 50);
    [UrlBtn setImage:[UIImage imageNamed:@"TwoDimensional_02"] forState:UIControlStateNormal];
    [UrlBtn setTitle:@"URL" forState:UIControlStateNormal];
    [UrlBtn addTarget:self action:@selector(ClickUrlBtn) forControlEvents:UIControlEventTouchUpInside];
    [UrlBtn setEnabled:NO];
    [self.view addSubview:UrlBtn];
    
    //添加短信按钮
    SmsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    SmsBtn.frame = CGRectMake(self.view.frame.size.width*2/4, 44, self.view.frame.size.width/4, 50);
    [SmsBtn setImage:[UIImage imageNamed:@"TwoDimensional_03"] forState:UIControlStateNormal];
    [SmsBtn setTitle:@"短信" forState:UIControlStateNormal];
    [SmsBtn addTarget:self action:@selector(ClickSmsBtn) forControlEvents:UIControlEventTouchUpInside];
    [SmsBtn setEnabled:NO];
    [self.view addSubview:SmsBtn];
    
    //添加联系人信息按钮
    ContactInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    ContactInfoBtn.frame = CGRectMake(self.view.frame.size.width*3/4, 44, self.view.frame.size.width/4, 50);
    [ContactInfoBtn setImage:[UIImage imageNamed:@"TwoDimensional_04"] forState:UIControlStateNormal];
    [ContactInfoBtn setTitle:@"联系人" forState:UIControlStateNormal];
    [ContactInfoBtn addTarget:self action:@selector(ClickContactInfoBtn) forControlEvents:UIControlEventTouchUpInside];
    [ContactInfoBtn setEnabled:NO];
    [self.view addSubview:ContactInfoBtn];
    
    //添加取消按钮
    CancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CancelBtn.frame = CGRectMake(self.view.frame.size.width*4/4, 44, self.view.frame.size.width/4, 50);
    [CancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [CancelBtn addTarget:self action:@selector(ClickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [CancelBtn setEnabled:NO];
    [self.view addSubview:CancelBtn];
    
    //添加图片显示
    imageview = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-250)/2, (self.view.frame.size.height-300)/2+44, 250, 250)];
    [self.view addSubview:imageview];
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

//处理点击扫描事件
-(void) ClickScanningBtn
{
    Reader = [ZBarReaderViewController new];
    Reader.readerDelegate = self;
    Reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    
    ZBarImageScanner *scanner = Reader.scanner;
    
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    
    [self presentModalViewController: Reader
                            animated: YES];
}

//处理点击URL事件
-(void) ClickUrlBtn
{
    NSLog(@"------------%@",self.UrlContent);
    
    NSString * url = [NSString stringWithFormat:@"网址:%@",self.UrlContent];
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:url delegate:nil cancelButtonTitle:@"进入" otherButtonTitles:@"取消",nil];
    alertView.tag =167;
    [alertView show];
    alertView.delegate = self;
    [alertView release];
}

//处理点击短信事件
-(void) ClickSmsBtn
{
    //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
    MFMessageComposeViewController* controller = [[MFMessageComposeViewController alloc] init];
    if ([MFMessageComposeViewController canSendText]) {
        controller.body =  self.Message;
        //parse through receipients
        NSScanner* numberScanner = [NSScanner scannerWithString:self.Number];
        [numberScanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@","]];
        NSCharacterSet* charactersToSkip = [NSCharacterSet characterSetWithCharactersInString:@","];
        NSString* substring = @"";
        NSMutableArray *substrings = [NSMutableArray array];
        while (![numberScanner isAtEnd]) {
            [numberScanner scanUpToCharactersFromSet:charactersToSkip intoString:&substring];
            [numberScanner scanCharactersFromSet:charactersToSkip intoString:NULL];
            NSLog(@"%@", substring);
            [substrings addObject:substring];
        }
        
        controller.recipients = substrings;
        controller.messageComposeDelegate = self;
        [self presentModalViewController:controller animated:YES];
    }
}

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissModalViewControllerAnimated:YES];
    if (result == MessageComposeResultCancelled)
        NSLog(@"Message cancelled");
    else if (result == MessageComposeResultSent)
        NSLog(@"Message sent");
    else
        NSLog(@"Message failed");
}

//处理点击联系人事件
-(void) ClickContactInfoBtn
{
    
    addressBook = ABAddressBookCreate();
    
    //初始化一个record
    person = ABPersonCreate();
    //这是一个空的记录，或者说是没有任何信息的联系人
    //下面给这个人 添加一个名字
    NSString *firstName = self.FamilyName;
    ABRecordSetValue(person, kABPersonFirstNameProperty, (CFStringRef)firstName, NULL);
    NSString *lastName = self.FirstName;
    ABRecordSetValue(person, kABPersonLastNameProperty, (CFStringRef)lastName, NULL);
    
    ABRecordSetValue(person, kABPersonOrganizationProperty,self.Company, NULL);
    ABRecordSetValue(person, kABPersonJobTitleProperty,self.JobTitle, NULL);
    
    ABMutableMultiValueRef multiURL = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiURL, self.CompanyUrl, kABHomeLabel, NULL);
    ABRecordSetValue(person, kABPersonURLProperty, multiURL, NULL);
    CFRelease(multiURL);
    
    //这些都是单一值属性的设置，接下来看看多值属性的设置
    NSArray *phones = [NSArray arrayWithObjects:self.Telephone,self.CallNumber,self.FaxTelephone,nil];
    NSArray *labels = [NSArray arrayWithObjects:@"手机", @"电话", @"传真电话",nil];
    //初始化一个多值对象，类似字典
    
    ABMutableMultiValueRef mulRef = ABMultiValueCreateMutable(kABMultiStringPropertyType);

    //循环设置值
    for(int i = 0; i < phones.count; i++)
    {
        ABMultiValueIdentifier multivalueIdentifier;
        ABMultiValueAddValueAndLabel(mulRef, (CFStringRef)[phones objectAtIndex:i], (CFStringRef)[labels objectAtIndex:i], &multivalueIdentifier);
    }
    
    ABRecordSetValue(person, kABPersonPhoneProperty, mulRef, NULL);
    if(mulRef)
    CFRelease(mulRef);
    
    //EMAIL
    ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiEmail, self.Email, kABWorkLabel, NULL);
    ABRecordSetValue(person, kABPersonEmailProperty, multiEmail, NULL);
    CFRelease(multiEmail);
    
    //Address地址
    ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
    NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
    [addressDictionary setObject:self.Street forKey:(NSString *) kABPersonAddressStreetKey];
    [addressDictionary setObject:self.City forKey:(NSString *)kABPersonAddressCityKey];
    [addressDictionary setObject:self.Province forKey:(NSString *)kABPersonAddressStateKey];
    [addressDictionary setObject:self.PostalCode forKey:(NSString *)kABPersonAddressZIPKey];
    ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);
    ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,NULL);
    CFRelease(multiAddress);
    
    NSString * alertStr = [NSString stringWithFormat:@"您要添加的联系人信息为:手机号码:%@,姓名:%@%@",self.Telephone,self.FirstName,self.FamilyName];
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:alertStr delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
    [alertView show];
    alertView.delegate = self;
    [alertView release];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"------------%d",alert.tag);
    
    switch(alert.tag)
    {
        case 168:
            if (buttonIndex == [alert cancelButtonIndex])
                //默认cancelButtonIndex = 0，每个按钮index可设
            {
                //将新的记录，添加到通讯录中
                ABAddressBookAddRecord(addressBook, person, NULL);
                
                //通讯录执行保存
                
                ABAddressBookSave(addressBook, NULL);
                
                if(addressBook)
                    CFRelease(addressBook); 
            }
            break;
        case 167:
            if (buttonIndex == [alert cancelButtonIndex])
                //默认cancelButtonIndex = 0，每个按钮index可设
            {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.UrlContent]];
            }
            else 
            {
            }
            return;
        default:
            break;
    }
}

//处理点击取消事件
-(void) ClickCancelBtn
{
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"正在建设中，请期待!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    [alert release];
    return;
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    id<NSFastEnumeration> results =[info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;
    
    imageview.image =[info objectForKey: UIImagePickerControllerOriginalImage];
    [reader dismissModalViewControllerAnimated: YES];
    
    //判断是否包含 头'http:' 即属于URL类型
    NSString *regex = @"http+:[^\\s]*";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    
    //判断是否包含 头'MECARD:' 即属于联系人类型
    NSString *mecardid = @"MECARD:";
    //NSPredicate *mecardPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mecardid];
    
    //判断是否包含 头‘SMSTO:’ 即属于短信类型
    NSString *smsto = @"SMSTO+:[^\\s]*";;
    NSPredicate *smstoPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",smsto];
    
    NSString * Str;
    Str =  symbol.data;
    
    //symbol.data;
    
    //处理部分中文乱码问题
    
    if ([Str canBeConvertedToEncoding:NSShiftJISStringEncoding])
    {
        Str = [NSString stringWithCString:[Str cStringUsingEncoding: NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];        
    }
    
    NSString * MeCard = [Str substringToIndex:7];
    NSLog(@"=========%@",Str);
    
    if ([predicate evaluateWithObject:Str])
    {
        [UrlBtn setEnabled:YES];
        [SmsBtn setEnabled:NO];
        [ContactInfoBtn setEnabled:NO];
        [CancelBtn setEnabled:NO];
        self.UrlContent = Str;
        NSLog(@"------------%@",self.UrlContent);
    }
    else if([mecardid isEqualToString:MeCard])
    {
        [UrlBtn setEnabled:NO];
        [SmsBtn setEnabled:NO];
        [ContactInfoBtn setEnabled:YES];
        [CancelBtn setEnabled:NO];
        
        ContactInfoContent = Str;
        ContactInfoArray = [ContactInfoContent componentsSeparatedByString:@";"];
        for (int i =0; i<[ContactInfoArray count]; i++)
        {
            if (i==0)
            {
                NSString * FullName = [ContactInfoArray objectAtIndex:i];
                NSArray * NameArray = [FullName componentsSeparatedByString:@","];
                for (int j=0; j<[NameArray count]; j++)
                {
                    if (j==0)
                    {
                        self.FirstName = [NameArray objectAtIndex:j];
                        NSArray * FirstArray = [self.FirstName componentsSeparatedByString:@":"];
                        self.FirstName = [FirstArray objectAtIndex:2];
                        NSLog(@"%@",self.FirstName);
                    }
                    else if(j==1)
                    {
                        self.FamilyName = [NameArray objectAtIndex:j];
                        NSLog(@"%@",self.FamilyName);
                    }
                }

            }
            else if(i==1)
            {
                NSString * TelNumber = [ContactInfoArray objectAtIndex:i];
                NSArray * TelArray = [TelNumber componentsSeparatedByString:@":"];
                self.CallNumber = [TelArray objectAtIndex:1];
                NSLog(@"%@",self.CallNumber);
            }
            else if(i==2)
            {
                NSString * TelNumber = [ContactInfoArray objectAtIndex:i];
                NSArray * TelArray = [TelNumber componentsSeparatedByString:@":"];
                self.Telephone = [TelArray objectAtIndex:1];
                NSLog(@"%@",self.Telephone);
            }
            else if(i==3)
            {
                NSString * TelNumber = [ContactInfoArray objectAtIndex:i];
                NSArray * TelArray = [TelNumber componentsSeparatedByString:@":"];
                self.FaxTelephone = [TelArray objectAtIndex:1];
                NSLog(@"%@",self.FaxTelephone);
            }
            else if(i==4)
            {
                NSString * email = [ContactInfoArray objectAtIndex:i];
                NSArray * emailArray = [email componentsSeparatedByString:@":"];
                self.Email = [emailArray objectAtIndex:1];
                NSLog(@"%@",self.Email);
            }
            else if(i==5)
            {
                NSString * companyrul = [ContactInfoArray objectAtIndex:i];
                NSArray * companyrulArray = [companyrul componentsSeparatedByString:@":"];
                self.CompanyUrl = [companyrulArray objectAtIndex:1];
                NSLog(@"%@",self.CompanyUrl);
            }
            else if(i==6)
            {
                NSString * AddressTemp = [ContactInfoArray objectAtIndex:i];
                NSArray * AddressArrayTemp = [AddressTemp componentsSeparatedByString:@":"];
                NSString * Address = [AddressArrayTemp objectAtIndex:1];
                NSArray * addrArray = [Address componentsSeparatedByString:@","];
                for (int k=0; k<[addrArray count]; k++)
                {
                    if (k==2)
                    {
                        self.Street = [addrArray objectAtIndex:k];
                        NSLog(@"%@",self.Street);
                    }
                    else if(k==3)
                    {
                        self.City = [addrArray objectAtIndex:k];
                        NSLog(@"%@",self.City);
                    }
                    else if(k==4)
                    {
                        self.Province = [addrArray objectAtIndex:k];
                        NSLog(@"%@",self.Province);
                    }
                    else if(k==5)
                    {
                        self.PostalCode = [addrArray objectAtIndex:k];
                        NSLog(@"%@",self.PostalCode);
                    }
                }
            }
            else if(i==7)
            {
                NSString * companyinfotemp = [ContactInfoArray objectAtIndex:i];
                NSArray * companyinforArray = [companyinfotemp componentsSeparatedByString:@":"];
                NSString * companyinfo= [companyinforArray objectAtIndex:1];
                NSArray * companyinfoArray = [companyinfo componentsSeparatedByString:@" "];
                for (int k =0; k<[companyinfoArray count]; k++)
                {
                    if (k==0)
                    {
                        self.JobTitle = [companyinfoArray objectAtIndex:k];
                    }
                    else if(k==1)
                    {
                        self.Company = [companyinfoArray objectAtIndex:k];
                    }
                }
            }
        }
    }
    else if([smstoPre evaluateWithObject:Str])
    {
        [UrlBtn setEnabled:NO];
        [SmsBtn setEnabled:YES];
        [ContactInfoBtn setEnabled:NO];
        [CancelBtn setEnabled:NO];
        
        SmsContent = Str;
        theArray = [SmsContent componentsSeparatedByString:@":"];
        for (int i =0 ; i<[theArray count]; i++)
        {
            if (i==1)
            {
                self.Number = [theArray objectAtIndex:i];
                NSLog(@"=========%@",self.Number);
            }
            else if(i==2)
            {
                self.Message = [theArray objectAtIndex:i];
                NSLog(@"=========%@",self.Message);
            }
        }
    }
    else
    {
        [UrlBtn setEnabled:NO];
        [SmsBtn setEnabled:NO];
        [ContactInfoBtn setEnabled:NO];
        [CancelBtn setEnabled:YES];
    }
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    [ScanningBtn release];
    [UrlBtn release];
    [SmsBtn release];
    [CancelBtn release];
    [ContactInfoBtn release];
    [imageview release];
    [UrlContent release];
    [Reader release];
    [Number release];
    [Message release];
    [theArray release];
    [ContactInfoArray release];
    [ContactInfoContent release];
    [FirstName release];
    [FamilyName release];
    [FaxTelephone release];
    [Telephone release];
    [CallNumber release];
    [Email release];
    [CompanyUrl release];
    [Street release];
    [Province release];
    [City release];
    [PostalCode release];
    [Company release];
    [JobTitle release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
